home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / asm_msc1.arc / EX45.ASM < prev    next >
Assembly Source File  |  1988-11-20  |  1KB  |  35 lines

  1. TITLE  Square Root (EX44.ASM)
  2.           PAGE      ,132
  3. OUR_CODE  SEGMENT   PARA 'CODE'
  4.       PUBLIC    SQRT32
  5. SQRT32    PROC      FAR
  6.           ASSUME    CS:OUR_CODE
  7.       PUSH      BP             ;Save contents of BP
  8.       PUSH      DX             ; and source number DX:AX
  9.       PUSH        AX
  10.       MOV        BP,SP         ;BP points to AX on the stack
  11.       MOV       BX,200         ;As a first approx,
  12.       DIV       BX             ; divide source number by 200,
  13.       ADD        AX,2         ; then add 2
  14. NXT_APP:  MOV        BX,AX         ;Save this approx. in BX
  15.       MOV        AX,[BP]         ;Read source number again
  16.       MOV       DX,[BP+2]
  17.       DIV       BX             ;Divide by last approx.
  18.       ADD        AX,BX         ;Average last two approxs.
  19.       SHR       AX,1
  20.       CMP       AX,BX         ;Last two approxs. identical?
  21.       JE        DONE
  22.       SUB       BX,AX         ; No. Check for diff. of 1
  23.       CMP        BX,1
  24.       JE        DONE
  25.       CMP        BX,-1
  26.       JNE       NXT_APP
  27. DONE:      MOV        BX,AX         ;Put result in BX
  28.       POP        AX             ;Restore source number
  29.       POP        DX
  30.       POP        BP             ; and scratch register BP
  31.       RET
  32. SQRT32    ENDP
  33. OUR_CODE  ENDS
  34.          END       SQRT32
  35.